export default {
  // #ifdef APP-PLUS
  methods: {
    /**
     * 微信App登录
     *  "openId": "o0yywwGWxtBCvBuE8vH4Naof0cqU",
     *	"nickName": "S .",
     *	"gender": 1,
     *	"city": "临沂",
     *	"province": "山东",
     *	"country": "中国",
     *	"avatarUrl": "http://thirdwx.qlogo.cn/mmopen/vi_32/xqpCtHRBBmdlf201Fykhtx7P7JcicIbgV3Weic1oOvN6iaR3tEbuu74f2fkKQWXvzK3VDgNTZzgf0g8FqPvq8LCNQ/132",
     *	"unionId": "oYqy4wmMcs78x9P-tsyMeM3MQ1PU"
     */
    loginByWxApp(userInfoData) {
      if (!this.agreement2) {
        this.$util.msg("请阅读并同意用户服务及隐私协议");
        this.$refs.confirmBtn.stop();
        return;
      }
      if (!this.agreement) {
        this.$util.msg("请阅读并同意第三方合作清单");
        this.$refs.confirmBtn.stop();
        return;
      }
      this.$util.throttle(async () => {
        let [err, res] = await uni.login({
          provider: "weixin",
        });

        console.log("🚀 ~ this.$util.throttle ~ res:", res);
        if (err) {
          console.log(err);
          return;
        }
        uni.getUserInfo({
          provider: "weixin",
          success: async (res2) => {
            console.log("🚀 ~ success: ~ res2:", res2);
            const params = {
              code: res.code,
              encryptedData: res2.encryptedData,
              iv: res2.iv,
            };
            const response = await this.$http.post(
              `/rest/login/carrierUserWx`,
              params
            );

            console.log("🚀 ~ success: ~ response:", response);
            // const response = await this.$request(
            //   "user",
            //   "loginByWeixin",
            //   {
            //     userInfo: res.userInfo,
            //   },
            //   {
            //     showLoading: true,
            //   }
            // );
            // if (response.status === 0) {
            //   this.$util.msg(response.msg);
            //   return;
            // }
            // if (response.hasBindMobile && response.data.token) {
            //   this.loginSuccessCallBack({
            //     token: response.data.token,
            //     tokenExpired: response.data.tokenExpired,
            //   });
            // } else {
            //   this.navTo(
            //     "/pages/auth/bindMobile?data=" + JSON.stringify(response.data)
            //   );
            // }
            plus.oauth.getServices((oauthRes) => {
              oauthRes[0].logout(
                (logoutRes) => {
                  console.log(logoutRes);
                },
                (error) => {
                  console.log(error);
                }
              );
            });
          },
          fail(err) {
            console.log(err);
          },
        });
      });
    },
  },
  // #endif
};
